package com.cszjzx.member.action;

import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.cszjzx.member.po.Stage;
import com.cszjzx.member.service.StageService;
import com.cszjzx.member.service.StageServiceImpl;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class EditStage extends ActionSupport{
	private int stageId;
	private String stageName;
	private String message;
	HttpServletRequest request = ServletActionContext.getRequest();
	private StageService stageService = new StageServiceImpl();
	
	
	
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public int getStageId() {
		return stageId;
	}
	public void setStageId(int stageId) {
		this.stageId = stageId;
	}
	public String getStageName() {
		return stageName;
	}
	public void setStageName(String stageName) {
		this.stageName = stageName;
	}
	
	public String showEdit(){
		try {
			stageName = new String(stageName.getBytes("iso-8859-1"),"utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return "showEditSuccess";
	}
	
	@SuppressWarnings("unchecked")
	public String edit(){
		List<Stage> stages = (List<Stage>)request.getSession().getAttribute("stages");
		Stage s = new Stage();
		for(int i=0;i<stages.size();i++){
			if(stageId == stages.get(i).getId()){
				s = stages.get(i);
				break;
			}
		}
		s.setName(stageName);
		if(stageService.editStage(s)){
			message="修改成功！";
			return "editSuccess";
		}
		else {
			message = "修改失败！";
			return "editError";
		}
	}
	
}
